package com.tjcd.project.library_base.base.easyhttpnet;

import androidx.annotation.NonNull;

import com.hjq.http.config.IRequestApi;
import com.hjq.http.listener.OnHttpListener;
import com.tjcd.project.library_base.base.bean.BaseResponseBean;

/**
 * @Author jiangKunKun
 * @CreateDate 2025/3/12
 * @Description
 * @SpittingGrooves
 */
public abstract class EasyHttpCallbackProxy<T extends BaseResponseBean> implements OnHttpListener<T> {

    @Override
    public void onHttpSuccess(@NonNull T result) {
        if ("200".equals(result.getCode())) {
            onDataSuccess(result);
        } else {
            onDataFail(Integer.parseInt(result.getCode()), result.getMsg(), result);
        }
    }

    @Override
    public void onHttpEnd(@NonNull IRequestApi api) {
        OnHttpListener.super.onHttpEnd(api);
    }

    @Override
    public void onHttpFail(@NonNull Throwable throwable) {

    }

    @Override
    public void onHttpStart(@NonNull IRequestApi api) {
        OnHttpListener.super.onHttpStart(api);
    }

    @Override
    public void onHttpSuccess(@NonNull T result, boolean cache) {
        OnHttpListener.super.onHttpSuccess(result, cache);
    }

    /**
     * 接口请求成功 code是成功
     * @param data 可能是null
     */
    public abstract void onDataSuccess(T data);

    /**
     * 接口请求成功 code是失败
     * data 特殊处理使用
     * @param code 接口code
     * @param message 接口message
     * @param data 可能是null
     */
    public abstract void onDataFail(int code, String message, T data);
}
